package com.solcoo.merchant.ui.level;

import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.android.common.util.DialogUtil;
import com.android.common.util.DialogUtil.SuccessPositiveListener;
import com.solcoo.merchant.ApplicationExt;
import com.solcoo.merchant.Constant;
import com.solcoo.merchant.R;
import com.solcoo.merchant.base.BaseActivity;
import com.solcoo.merchant.base.task.TaskHelper;
import com.solcoo.merchant.base.task.TaskHelper.Callback;
import com.solcoo.merchant.base.task.TaskHelper.DefaultCallback;
import com.solcoo.merchant.model.BaseDO;
import com.solcoo.merchant.util.CheckUtil;
import com.solcoo.merchant.util.CheckUtil.CheckResult;

public class AddLevelActivity extends BaseActivity {

	public static final String INTENT_KEY = "levelValue";

	private int level;

	EditText discount;

	EditText exp;

	private Dialog mDialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_level);
		level = getIntent().getIntExtra(INTENT_KEY, 0) + 1;
		TextView levelView = (TextView) findViewById(R.id.level_value);
		levelView.setText(String.valueOf(level));
		discount = (EditText) findViewById(R.id.discount);
		exp = (EditText) findViewById(R.id.exp);
		mDialog = DialogUtil.createDialog(this, new SuccessPositiveListener(
				this), null, null, "添加成功", null);
	}

	private Callback<BaseDO> callback = new DefaultCallback<BaseDO>(this) {

		@Override
		public void onSuccess(BaseDO result) {
			mDialog.show();
		}
	};

	public void sendOnClick(View v) {
		String expValue = exp.getText().toString();
		String discountValue = discount.getText().toString();
		CheckResult result = CheckUtil.checkAddLevel(discountValue, expValue);
		if (result.isSuccess()) {
			TaskHelper.oper(v.getContext(), Constant.URL.getAddLevel(
					ApplicationExt.getUser().yonghum, level, expValue,
					discountValue), callback, BaseDO.class);
		}
	}

}
